package com.itheima.controller;


import com.itheima.annotion.Log;
import com.itheima.common.PageBean;
import com.itheima.common.R;
import com.itheima.dto.StudentDto;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import com.itheima.vo.StudentVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学员表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-28
 */
@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public R pageQuery(StudentDto student) {

        PageBean<StudentVo> pageBean=studentService.pageQuery(student);
        return R.ok(pageBean);
    }
    @Log
    @PostMapping
    public R add(@RequestBody  Student student){
        studentService.insert(student);
        return R.ok();
    }
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id){
        Student student=studentService.selectById(id);
        return R.ok(student);
    }
    @PutMapping
    public R update(@RequestBody Student student) {
        studentService.update(student);
        return R.ok();
    }
    @PutMapping("violation/{id}/{score}")
    public R voUpdate(@PathVariable Integer id,@PathVariable Integer score){
     studentService.vo(id,score);
        return R.ok();
    }
    //@DeleteMapping("/{id}")
    public R delete(@PathVariable Integer id){
        studentService.delete(id);
        return R.ok();
    }
    @DeleteMapping("/{ids}")
    public R deletes( @PathVariable List<Integer> ids){
        log.info("ids:{}",ids);
        studentService.deletes(ids);
        return R.ok();
    }

}
